# Makefile example

# Compiler and flags
CC = gcc
CFLAGS = -Wall -g

# Target name
TARGET = snake_game

# Source files
SRCS = src/main.c src/init.c src/config.c src/snake.c

# Object files, with build/ prefix
OBJS = $(addprefix build/,$(notdir $(SRCS:.c=.o)))

# Include the header files directory
INCLUDES = -Isrc

# Default target
all: $(TARGET)

# Rule to build the executable
$(TARGET): $(OBJS)
	$(CC) $(OBJS) -o $@

# Rule to compile source files into object files
build/%.o: src/%.c
	$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
	@mkdir -p $(dir $@)

# Clean up object files and executable
clean:
	rm -f $(OBJS) $(TARGET)

# Very clean, removes the build directory too
distclean: clean
	rm -rf build

# Print help information
help:
	@echo "Available targets:"
	@echo "   all: builds the $(TARGET)"
	@echo "   clean: removes object files and $(TARGET)"
	@echo "   distclean: performs a clean and removes the build directory"
	@echo "   help: prints this message"

r:
	make all
	./$(TARGET)

# Default rule when no target is specified
.PHONY: all clean distclean help r